package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CategoryMapper {
    @Select("select * from category where name=#{name}")
    Category findByName(String name);

    @Insert("insert into category " +
            "values(null,#{type},#{name},#{sort},#{createTime}," +
            "#{updateTime},#{createUser},#{updateUser}) ")
    Integer save (Category category);

    @Select("SELECT * FROM category order by sort")
    List<Category>findByPage();

    @Delete("delete from category where id=#{id}")
    Integer delete (long id);

    @Update("update category " +
            "set name=#{name},sort=#{sort},update_user=#{updateUser},update_time=#{updateTime}" +
            "where id=#{id}")
    Integer update(Category category);

    @Select("select count(*) from category where name=#{name} and id!=#{id}")
    Integer selectByNameCount(Category category);

    List<Category>findAllByType(Integer type);


    @Select("select * from category where id=#{cid}")
    Category findByCid(Long cid);
}
